home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume7 / tput < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  6.8 KB

  1. Subject:  v07i024:  Public-domain tput(1) program
  2. Newsgroups: mod.sources
  3. Approved: mirror!rs
  4.  
  5. Submitted by: seismo!rochester!ur-valhalla!badri (Badri Lokanathan)
  6. Mod.sources: Volume 7, Issue 24
  7. Archive-name: tput
  8.  
  9. I am enclosing "my version" of the system V utility tput. The shar file
  10. contains a C source file, a README, a Makefile and a man page.  Since I
  11. do not have access to a system V machine I cannot vouch for
  12. compatibility.
  13.     Badri Lokanathan
  14. --------------------CUT HERE--------------------
  15. #! /bin/sh
  16. # This is a shell archive, meaning:
  17. # 1. Remove everything above the #! /bin/sh line.
  18. # 2. Save the resulting text in a file.
  19. # 3. Execute the file with /bin/sh (not csh) to create:
  20. #    README
  21. #    tput.1
  22. #    tput.c
  23. #    Makefile
  24. # This archive created: Thu Aug 28 10:36:38 1986
  25. export PATH; PATH=/bin:/usr/bin:$PATH
  26. if test -f 'README'
  27. then
  28.     echo shar: "will not over-write existing file 'README'"
  29. else
  30. cat << \SHAR_EOF > 'README'
  31. >From rochester!ur-valhalla!badri  Aug 28 10:02
  32. To: whom it may concern
  33. Subject: tput instructions
  34.  
  35. This program is supposed to be equivalent to the system V utility
  36. tput, which handles screen parameters from termcap. It may take inputs
  37. in a slightly different format (basically because I wrote this program
  38. without actually having worked on the system V tput.) I suppose the
  39. man page is different too! Any suggestions/modifications are welcome.
  40.  
  41. Your system is assumed to have termlib and associated functions (I
  42. wrote the program on BSD 4.2, assuming that termlib was fairly
  43. standard.) There is one include file in the program - sgtty.h which
  44. should be present. If not, I hope an equivalent exists.
  45. Other than that, the code should be fairly portable, since there
  46. isn't much to it!
  47.  
  48. The make file is delibrately trivial. It does not do any installation
  49. - just compilation.
  50.  
  51. make
  52.  
  53. will make tput in the current directory.
  54.  
  55. make man
  56.  
  57. will make a man page in tput.doc.
  58.  
  59.  
  60. tput, written by Badri Lokanathan, is in the public domain, and may be
  61. used by any person or organization, in any way and for any purpose.
  62. There is no warranty of merchantability nor any warranty of fitness for
  63. a particular purpose nor any other warranty, either express or implied,
  64. as to the accuracy of the enclosed materials or as to their suitability
  65. for any particular purpose.  Accordingly, the author assumes no respon-
  66. sibility for their use by the recipient.   Further, the author assumes
  67. no obligation to furnish any assistance of any kind whatsoever, or to
  68. furnish any additional information or documentation.
  69. SHAR_EOF
  70. fi
  71. if test -f 'tput.1'
  72. then
  73.     echo shar: "will not over-write existing file 'tput.1'"
  74. else
  75. cat << \SHAR_EOF > 'tput.1'
  76. .TH tput 1local "UR EE GRADUATE VLSI LAB"
  77. .SH NAME
  78. tput \- Change terminal display characteristics.
  79. .SH SYNOPSIS
  80. .B  tput option
  81. [
  82. .I "x"
  83. .I "y"
  84. ]
  85. .SH DESCRIPTION
  86. .I tput
  87. sends a sequence of characters corresponding to the operation
  88. specified in option. It is intended to emulate the system V utility
  89. tput.
  90. .PP
  91. Option is a two letter capability as specified in termcap(5).
  92. x and y are integer values for cursor movement.
  93. Typical options are given below.
  94. .SH REQUESTS
  95. .ti0
  96. .I "Option            Explanation"
  97. .ti0
  98. .li
  99. bl                Beep the terminal
  100. .ti0
  101. .li
  102. cl                Clear screen
  103. .ti0
  104. .li
  105. mb                Blink line
  106. .ti0
  107. .li
  108. md                Highlight line
  109. .ti0
  110. .li
  111. me                Restore normal mode
  112. .ti0
  113. .li
  114. mr                Reverse video line
  115. .ti0
  116. .li
  117. se                End Standout mode
  118. .ti0
  119. .li
  120. so                Begin Standout mode
  121. .ti0
  122. .li
  123. ue                End underlining mode
  124. .ti0
  125. .li
  126. us                Start underlining mode
  127. .PP
  128. A typical cursor addressing option would be set scroll region (if supported):
  129. .PP
  130. tput cs 5 3
  131. .PP
  132. would set the scrolling between lines 3 and 5.
  133. .SH FILES
  134. /etc/termcap
  135. .SH SEE ALSO
  136. termcap(3X), termcap(5)
  137. .SH DIAGNOSTICS
  138. Returns 0 if it worked; else returns 1.
  139. .SH BUGS
  140. .PP
  141. The onus of handling unavailable options is on the user.
  142. .SH AUTHOR
  143. Badri Lokanathan
  144. SHAR_EOF
  145. fi
  146. if test -f 'tput.c'
  147. then
  148.     echo shar: "will not over-write existing file 'tput.c'"
  149. else
  150. cat << \SHAR_EOF > 'tput.c'
  151. #ifndef LINT
  152. static char rcsid[] = "$Header: tput.c,v 1.2 86/08/22 13:39:27 badri Exp $" ;
  153. #endif LINT
  154. /*
  155.  * Copyright (C) $Date: 86/08/22 13:39:27 $
  156.  * by $Author: badri $
  157.  * University of Rochester,
  158.  * Department of Electrical Engineering.
  159.  *
  160.  * CoNtEnTs   This file contains a program to emulate the system V
  161.  * CoNtEnTs   version of tput.
  162.  *
  163.  * $Locker: badri $
  164.  * $Source: /u/users/badri/usr/src/local/tput/RCS/tput.c,v $
  165.  * $Revision: 1.2 $
  166.  *
  167.  * History of this release:
  168.  * $Log:    tput.c,v $
  169.  * Revision 1.2  86/08/22  13:39:27  badri
  170.  * 1. Corrected a bug that would cause %d to fail after %%.
  171.  * 2. Included XTABS handling.
  172.  * 3. General cleanup of code.
  173.  * 
  174.  * Revision 1.1  86/08/21  19:23:33  badri
  175.  * Initial revision
  176.  * 
  177.  */
  178. #include <sgtty.h>
  179.  
  180. #ifndef XTABS
  181. #define XTABS 0006000
  182. #endif  XTABS
  183.  
  184. #define LARGEBUF 1024
  185. #define SMALLBUF   64
  186. #define OUTPUT      1
  187. #define SUCCESS     0
  188. #define FAILURE     1
  189. #define AFFLINES    1
  190.  
  191. int errno;
  192.  
  193. main(argc,argv)
  194. int argc;
  195. char *argv[];
  196. {
  197.     char bp[LARGEBUF], *getenv(), *tgetstr(), *tgoto(),
  198.          buf[SMALLBUF], *area, *ptr;
  199.     int outc();
  200.     struct sgttyb ttyprm;
  201.     short ttyflg;
  202.  
  203.     if (argc < 2) exit(FAILURE);
  204.  
  205.     switch (tgetent(bp,getenv("TERM")))
  206.     {
  207.         case -1:
  208.             exit(FAILURE);
  209.  
  210.         case  0:
  211.             exit(FAILURE);
  212.  
  213.         case  1:
  214.             break;
  215.     }
  216.     area = buf;
  217.     if (*(ptr=tgetstr(argv[1],&area)) == '\0') exit(FAILURE);
  218.  
  219.     /*
  220.      * Examine if cursor movement specified. This is done
  221.      * by looking for % followed by any but %. Since %%
  222.      * is a single %, we have to make sure that %% followed
  223.      * by any but % is not interpreted as a format.
  224.      * If cursor movement is specified then tgoto needs
  225.      * to be invoked. Else put as is.
  226.      */
  227.     ptr = buf;
  228.     while (*ptr != '\0')
  229.     {
  230.         if (*(ptr++) != '%') continue;
  231.         if (*ptr != '\0' && *(ptr++) != '%')
  232.         {
  233.             /* This string is a cm string. */
  234.             if (argc != 4) exit(FAILURE);
  235.  
  236.             if (*(ptr=tgoto(buf,atoi(argv[2]),atoi(argv[3]))) == 'O'
  237.                 && *(ptr+1) == 'O' && *(ptr+2) == 'P'
  238.                 && *(ptr+3) == 'S') exit(FAILURE);
  239.  
  240.             /* Turn off XTABS, but save old flags first. */
  241.             if (gtty(OUTPUT,&ttyprm) < 0) exit(errno);
  242.             ttyflg = ttyprm.sg_flags;
  243.  
  244.             ttyprm.sg_flags &= ~XTABS;
  245.             if (stty(OUTPUT,&ttyprm) < 0) exit(errno);
  246.  
  247.             tputs(ptr,AFFLINES,outc);
  248.  
  249.             /* Restore old flags. */
  250.             ttyprm.sg_flags = ttyflg;
  251.             if (stty(OUTPUT,&ttyprm) < 0) exit(errno);
  252.             exit(SUCCESS);
  253.         }
  254.     exit(FAILURE);
  255.     }
  256.     tputs(buf,AFFLINES,outc);
  257.     exit(errno);
  258. }
  259.  
  260. outc(c)
  261. char c;
  262. {
  263.     if (write(OUTPUT,&c,sizeof(char)) < 0) exit(errno);
  264.     return(SUCCESS);
  265. }
  266. SHAR_EOF
  267. fi
  268. if test -f 'Makefile'
  269. then
  270.     echo shar: "will not over-write existing file 'Makefile'"
  271. else
  272. cat << \SHAR_EOF > 'Makefile'
  273. tput: tput.c
  274.     cc -o tput tput.c -ltermlib
  275.  
  276. man: tput.1
  277.     nroff -man tput.1 > tput.doc
  278.  
  279. dtput: tput.c
  280.     cc -g -o dtput tput.c -ltermlib
  281. SHAR_EOF
  282. fi
  283. exit 0
  284. #    End of shell archive
  285.  
  286.